-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix axes flattening for single subplot case #3889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Abhirup Das <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR fixes a bug in the save_images_grid function in scripts/demos/sensors/cameras.py that occurs when displaying a single subplot. The issue stems from matplotlib's behavior where plt.subplots(nrow, ncol) returns a single Axes object for single subplots (when nrow=1 and ncol=1) instead of an array. The original code unconditionally called .flatten() on the axes, which caused an AttributeError when axes was a single object rather than an ndarray.
The fix adds a type check to handle both cases: if axes is an ndarray, it flattens it as before; otherwise, it wraps the single axis in a numpy array to maintain consistency for the subsequent loop that indexes into the axes array. This change ensures the camera demo visualization function works correctly regardless of whether it's displaying one image or multiple images in a grid layout.
Important Files Changed
| Filename | Score | Overview |
|---|---|---|
| scripts/demos/sensors/cameras.py | 1/5 | Fixed matplotlib axes handling for single subplot case but contains a syntax error (missing closing parenthesis) |
Confidence score: 1/5
- This PR cannot be merged due to a critical syntax error that will prevent the code from running
- Score is 1/5 because while the logic fix is correct and addresses a real matplotlib edge case, there's a missing closing parenthesis on line 144 that makes the code syntactically invalid
- The
scripts/demos/sensors/cameras.pyfile requires immediate attention to fix the syntax error before merge
Sequence Diagram
sequenceDiagram
participant User
participant Main
participant AppLauncher
participant SimulationContext
participant InteractiveScene
participant Robot
participant Camera
participant TiledCamera
participant RaycastCamera
participant ImageSaver
User->>Main: "Execute script with --enable_cameras"
Main->>AppLauncher: "Launch Isaac Sim app"
AppLauncher-->>Main: "Simulation app ready"
Main->>SimulationContext: "Initialize simulation context"
SimulationContext-->>Main: "Simulation ready"
Main->>SimulationContext: "Set camera view"
Main->>InteractiveScene: "Create scene with sensors config"
InteractiveScene->>Robot: "Spawn robot in environments"
InteractiveScene->>Camera: "Create standard camera sensor"
InteractiveScene->>TiledCamera: "Create tiled camera sensor"
InteractiveScene->>RaycastCamera: "Create raycast camera sensor"
InteractiveScene-->>Main: "Scene setup complete"
Main->>SimulationContext: "Reset simulation"
Main->>Main: "Start simulation loop"
loop "Simulation Loop (every frame)"
alt "Reset condition (every 500 iterations)"
Main->>Robot: "Reset root state and joint positions"
Main->>InteractiveScene: "Reset scene buffers"
end
Main->>Robot: "Set joint position targets"
Main->>InteractiveScene: "Write data to simulation"
Main->>SimulationContext: "Step simulation"
Main->>InteractiveScene: "Update sensor buffers"
Main->>Camera: "Get RGB and depth data"
Camera-->>Main: "Return image data"
Main->>TiledCamera: "Get RGB and depth data"
TiledCamera-->>Main: "Return image data"
Main->>RaycastCamera: "Get depth and normals data"
RaycastCamera-->>Main: "Return sensor data"
alt "Save images (every 10 iterations)"
Main->>ImageSaver: "Save RGB comparison grid"
Main->>ImageSaver: "Save depth comparison grid"
Main->>ImageSaver: "Save tiled RGB images"
Main->>ImageSaver: "Save camera RGB images"
end
end
1 file reviewed, 1 comment
scripts/demos/sensors/cameras.py
Outdated
| if isinstance(axes, np.ndarray): | ||
| axes = axes.flatten() | ||
| else: | ||
| axes = np.array([axes] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Missing closing parenthesis - this will cause a syntax error
| axes = np.array([axes] | |
| axes = np.array([axes]) |
Signed-off-by: Abhirup Das <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This review covers only the changes made since the last review, not the entire PR. The developer has successfully addressed the syntax error identified in the previous review by adding the missing closing parenthesis to line 144 in the save_images_grid function. The fix changes axes = np.array([axes] to axes = np.array([axes]), which resolves the critical syntax error that was preventing the camera demo script from running. This function is part of the camera sensor demonstration workflow in Isaac Lab, responsible for creating visualization grids of camera outputs from different sensor configurations including RGB cameras, depth cameras, and raycast cameras.
Important Files Changed
| Filename | Score | Overview |
|---|---|---|
| scripts/demos/sensors/cameras.py | 5/5 | Fixed missing closing parenthesis in save_images_grid function to resolve syntax error |
Confidence score: 5/5
- This PR is safe to merge with minimal risk as it fixes a critical syntax error
- Score reflects a simple, well-targeted fix that addresses the exact issue identified in the previous review with no additional complexity
- No files require special attention as this is a straightforward syntax correction
1 file reviewed, no comments
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
List any dependencies that are required for this change.
Fixes # (issue)
Type of change
Screenshots
Please attach before and after screenshots of the change if applicable.
| Before | After |


| ------ | ----- |
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there